﻿
using Abp.Application.Services.Dto;
using Abp.Web.Models;
using Abp.Web.Mvc.Authorization;
using KDS.Mes.Mes.TestPower2s;
using KDS.Mes.Mes.TestPower2s.Dtos;
using KDS.Mes.Web.Models.TestPower2s;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace KDS.Mes.Web.Controllers
{
    public class TestPower2sController : MesControllerBase
    {

        private readonly ITestPower2AppService _testPower2AppService;

        public TestPower2sController(ITestPower2AppService testPower2AppService)
        {
            _testPower2AppService = testPower2AppService;
           
        }

        public  ActionResult Index()
        {
            var lines = new List<ComboboxItemDto>();
            lines.Insert(0, new ComboboxItemDto("", ""));
            lines.Insert(1, new ComboboxItemDto("X001", "一线"));
            lines.Insert(2, new ComboboxItemDto("X002", "二线"));
            lines.Insert(3, new ComboboxItemDto("X003", "三线"));

            var model = new TestPower2sViewModel
            {
                FilterText = Request.QueryString["filterText"],
                Lines = lines
            };
            return View(model);
        }

        [DontWrapResult]
        public JsonResult GetAllTestPower2s(int limit, int offset, string sortfiled, string sortway,
                                   string lineId, string seatID, DateTime? time1, DateTime? time2)
        {
            var sort = !string.IsNullOrEmpty(sortfiled) ? string.Format("{0} {1}", sortfiled, sortway) : "";
            var filter = new GetTestPower2Input
            {
                SkipCount = offset,
                MaxResultCount = limit,
                Sorting = sort,
                LineId = lineId,
                SeatID = seatID,
                Time1 = time1,
                Time2 = time2,
            };
            var pagedTasks = _testPower2AppService.GetPagedTestPower2s(filter);
            return Json(new { total = pagedTasks.TotalCount, rows = pagedTasks.Items }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 根据id获取进行编辑或者添加的用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        //[AbpMvcAuthorize(TestPower2AppPermissions.TestPower2_CreateTestPower2,TestPower2AppPermissions.TestPower2_EditTestPower2)]
        public async Task<PartialViewResult> CreateOrEditTestPower2Modal(int? id)
        {
		var input=new NullableIdDto<int>{Id=id};
	 
                 var output=    await _testPower2AppService.GetTestPower2ForEditAsync(input);

				 var viewModel=new CreateOrEditTestPower2ModalViewModel(output);


            return PartialView("_CreateOrEditTestPower2Modal",viewModel);
        }
	 
       
    }
}